package com.seuic.hnjiningposapp.hnapps.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.cardview.widget.CardView;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.base.BaseActivity;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.AutomaticOperationPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.CounterfeitCurrencyDetectionPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DealSuccessPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DealingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DrawMoneyNumPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ErrorPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.InputPasswordPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.PrintingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ReadCardPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ReadCcP;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SureDealPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SurePrintPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SureToHelpFarmersWithdrawOtherPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ToHelpFarmersWithdrawOtherPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.VerifyCardPopup;
import com.seuic.hnjiningposapp.hnapps.util.Api;
import com.seuic.hnjiningposapp.hnapps.util.DealMoneyAndNumComparisonUtils;
import com.seuic.hnjiningposapp.hnapps.util.FTPUtils;
import com.seuic.hnjiningposapp.hnapps.util.FtpReadFileUtils;
import com.seuic.hnjiningposapp.hnapps.util.GetMoneyLvUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtilsV2;
import com.seuic.hnjiningposapp.hnapps.util.MoneyUtils;
import com.seuic.hnjiningposapp.hnapps.util.PrintUtil;
import com.seuic.hnjiningposapp.hnapps.util.TimeUtils;
import com.seuic.posdsdk.pos_func.PosFuncs;
import com.socks.library.KLog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * donghui
 * 2020年1月14日
 * 助农取款
 */
public class ToHelpFarmersWithdrawMoneyActivity extends BaseActivity implements
        CounterfeitCurrencyDetectionPp.CounterfeitCurrencyDCallBack,
        SureToHelpFarmersWithdrawOtherPp.SureToHelpFarmersCall, ToHelpFarmersWithdrawOtherPp.ToOtherHMoneyCall, ErrorPopup.OnFinishCallbacked, SureDealPopup.OnNextClicklistener, InputPasswordPopup.ClickCallback, DrawMoneyNumPopup.ClickCallback, DealSuccessPopup.ClickCallback, SurePrintPopup.ClickCallback {
    @BindView(R.id.drawmoney_local)
    Button drawmoneyLocal;//本行助农取款
    @BindView(R.id.drawmoney_other)
    Button drawmoneyOther;//他行助农取款
    @BindView(R.id.drawermoneyLayout)
    CardView drawermoneyLayout;//助农取款类型布局

    private String card_num; //卡号
    private String pass_word = "";

    private int drawmoneyType;//0:本行助农取款1:他行助农取款
    private String dealmoney;//交易金额
    private String PayeeActNo; //备付金账号
    private String PayeeActName;//备付金账号姓名
    private String PayeeBankNo;//收款行行号
    private String dealTime;//交易时间

    private VerifyCardPopup verifycardPop;
    private BasePopupView verifycardPopupView;
    private InputPasswordPopup inputpasswordPop;
    private BasePopupView inputpasswordPopupView;
    private DrawMoneyNumPopup drawmoneyNumPop;
    private BasePopupView drawmoneyNumPopupView;
    private DealingPopup dealingPop;
    private BasePopupView dealingPopupView;
    private DealSuccessPopup dealsuccessPop;
    private BasePopupView dealsuccessPopupView;
    private PrintingPopup printingPop;
    private BasePopupView printingPopupView;
    private SurePrintPopup surePrintPop;
    private BasePopupView surePrintPopupView;
    private BasePopupView AutomaticOperationPopupView;
    private AutomaticOperationPopup automaticOperationPopup;
    private ErrorPopup errorPopup;
    private BasePopupView errorPopupPpView;
    private SureDealPopup sureDealPopup;
    private BasePopupView sureDealPopupView;
    private ReadCardPopup readcardPop;
    private BasePopupView readcardPopupView;
    //加密的得到的密码秘闻
    private String cipassword;
    //账户姓名
    private String card_username;
    private String reserveFundAcctNo;
    private String reserveFundAcctName;
    private String openBrcNo;
    private String make_money;
    private String make_time;
    //流水号
    private String mServerSeqNo;
    private ToHelpFarmersWithdrawOtherPp toHelpFarmersWithdrawOtherPp;
    private BasePopupView toHelpFarmersWithdrawOtherPpView;
    private SureToHelpFarmersWithdrawOtherPp sureToHelpFarmersWithdrawOtherPp;
    private BasePopupView sureToHelpFarmersWithdrawOtherPpView;
    //他行余额
    private String otherUserBalance;
    //他行交易金额
    private String toherMakeMoney;
    private String track2Data;

    private CounterfeitCurrencyDetectionPp currencyDetectionPp;
    private BasePopupView currencyDetectionPpView;
    private String consumerSeqNo;
    private ReadCcP readCcP;
    private BasePopupView readCcPViewpp;

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_to_help_farmers_withdraw_money;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        this.setBackBtClick(R.id.base_back_btn);
        this.setTitleText("助农取款");
        findViewById(R.id.base_back_btn).setVisibility(View.INVISIBLE);
        readCcP = new ReadCcP(this);
        readCcPViewpp = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(readCcP);
        toHelpFarmersWithdrawOtherPp = new ToHelpFarmersWithdrawOtherPp(this, this);
        toHelpFarmersWithdrawOtherPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(toHelpFarmersWithdrawOtherPp);
        //确认验钞
        currencyDetectionPp = new CounterfeitCurrencyDetectionPp(this, this);
        currencyDetectionPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(currencyDetectionPp);
        errorPopup = new ErrorPopup(this, this);
        errorPopupPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(errorPopup);
        //验证账户信息界面
        readcardPop = new ReadCardPopup(this);
        //验证账户信息界面
        readcardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(readcardPop);
        verifycardPop = new VerifyCardPopup(this, this);
        verifycardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(verifycardPop);//验证账户信息界面
        inputpasswordPop = new InputPasswordPopup(this, this);
        inputpasswordPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(inputpasswordPop);//输入密码界面
        drawmoneyNumPop = new DrawMoneyNumPopup(this, this, this);
        drawmoneyNumPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(drawmoneyNumPop);//输入取款金额界面
        dealingPop = new DealingPopup(this, this);
        dealingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dealingPop);//交易中界面
        dealsuccessPop = new DealSuccessPopup(this, this, this);
        dealsuccessPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dealsuccessPop);//交易成功界面
        surePrintPop = new SurePrintPopup(this, this, this);
        surePrintPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(surePrintPop);//打印纸是否正常界面
        printingPop = new PrintingPopup(this, this);
        printingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(printingPop);//打印中界面
        new Thread(new Runnable() {
            @Override
            public void run() {
                FTPUtils.deleteFile(Api.FTPFILEADRESS, Api.FTPFILE);
            }
        }).start();
        //删除文件存储时对应目录下的文件
//        File file = new File(Api.FTPDOWNADRESSINFO);
//        file.delete();

    }

    /**
     * 确认输入的密码回调
     */
    @Override
    public void SendPassword(String password) {
        //输入确定之后隐藏
        KLog.e("密码加密");
        KLog.e(password + "card_num" + card_num);
        cipassword = HttpUtils.getResult(password, card_num);
        inputpasswordPopupView.dismiss();
        doSelfBank();
    }

    /**
     * 他行
     */
    private void doOtherBank() {
        showMakeHint("验证密码...");
        KLog.e("进行验证密码操作");
        HttpUtilsV2.getCurrentBalanceCheck(
                card_num,
                track2Data,
                "",
                cipassword,
                "",
                "05374610",
                "051",
                "",
                card_num, new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        card_username = rspBody.getString("CUST_NAME").trim();
                        otherUserBalance = rspBody.getString("ADDITIONAL_AMOUNT").substring(rspBody.getString("ADDITIONAL_AMOUNT").length() - 12, rspBody.getString("ADDITIONAL_AMOUNT").length());
                        runOnUiThread(() -> {
                            dismissshowMakeHint();
                            //查询交易次数交易金额
                            showMakeHint("查询交易次数交易金额...");
                            HttpUtilsV2.getQueryAccountNorm(card_num, new HttpUtilsV2.NetCallBack() {
                                @Override
                                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody11) {
                                    String TradeCount = rspBody11.getString("TradeCount");
                                    String TradeAmount = rspBody11.getString("TradeAmount");
                                    DealMoneyAndNumComparisonUtils.comparison(
                                            DealMoneyAndNumComparisonUtils.WITHDRAWAL,
                                            TradeCount,
                                            TradeAmount,
                                            (next, msg) -> {
                                                KLog.e(msg);
                                                if (next) {
                                                    runOnUiThread(() -> {
                                                        dismissshowMakeHint();
                                                        //查询交易次数交易金额
                                                        showMakeHint("获取备付金信息...");
                                                        HttpUtilsV2.getQueryBankCardInfo(SPStaticUtils.getString("CardNum"), new HttpUtilsV2.NetCallBack() {
                                                            @Override
                                                            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody111) {
                                                                openBrcNo = rspBody111.getString("OpenBrcNo");
                                                                reserveFundAcctName = rspBody111.getString("AcctName");
                                                                reserveFundAcctNo = rspBody111.getString("AcctNo");
                                                                runOnUiThread(() -> {
                                                                    dismissshowMakeHint();
                                                                    //弹出输入取款信息
                                                                    toHelpFarmersWithdrawOtherPp.setCard_num(card_num);
                                                                    toHelpFarmersWithdrawOtherPp.setUser_name(card_username);
                                                                    toHelpFarmersWithdrawOtherPp.setUserbalance(otherUserBalance);
                                                                    toHelpFarmersWithdrawOtherPpView.show();
                                                                });
                                                            }

                                                            @Override
                                                            public void onError(String code, String msg) {
                                                                showErr(msg);
                                                            }
                                                        });
                                                    });
                                                } else {
                                                    runOnUiThread(() -> {
                                                        showErr(msg);
                                                    });
                                                }

                                            });

                                }

                                @Override
                                public void onError(String code, String msg) {
                                    showErr(msg);
                                }
                            });
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                }
        );
    }

    /**
     * 本行操作
     */
    private void doSelfBank() {
        //弹出验证消息
        showMakeHint("验证密码...");
        KLog.e("进行验证密码操作");
        //验证密码成功
        HttpUtilsV2.getAccountPwdVerification(card_num, cipassword, new HttpUtilsV2.NetCallBack() {
            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                runOnUiThread(() -> {
                    KLog.e("验证密码成功,返回数据，进行获取客户信息");
                    dismissshowMakeHint();
                    showMakeHint("获取客户信息...");
                    HttpUtilsV2.getQueryBankCardInfo(card_num, new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody1) {
                            card_username = rspBody1.getString("AcctName");
                            runOnUiThread(() -> {
                                dismissshowMakeHint();
                                showMakeHint("黑名单验证...");
                                HttpUtilsV2.getCheckingBankCardBlacklist(card_num, card_username, new HttpUtilsV2.NetCallBack() {
                                    @Override
                                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                        runOnUiThread(() -> {
                                            dismissshowMakeHint();
                                            //查询交易次数交易金额
                                            showMakeHint("查询交易次数交易金额...");
                                            HttpUtilsV2.getQueryAccountNorm(card_num, new HttpUtilsV2.NetCallBack() {
                                                @Override
                                                public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody11) {
                                                    String TradeCount = rspBody11.getString("TradeCount");
                                                    String TradeAmount = rspBody11.getString("TradeAmount");


                                                    DealMoneyAndNumComparisonUtils.comparison(
                                                            DealMoneyAndNumComparisonUtils.WITHDRAWAL,
                                                            TradeCount,
                                                            TradeAmount,
                                                            (next, msg) -> {
                                                                KLog.e(msg);
                                                                if (next) {
                                                                    runOnUiThread(() -> {
                                                                        dismissshowMakeHint();
                                                                        //查询交易次数交易金额
                                                                        showMakeHint("获取备付金信息...");
                                                                        HttpUtilsV2.getQueryBankCardInfo(SPStaticUtils.getString("CardNum"), new HttpUtilsV2.NetCallBack() {
                                                                            @Override
                                                                            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody111) {
                                                                                openBrcNo = rspBody111.getString("OpenBrcNo");
                                                                                reserveFundAcctName = rspBody111.getString("AcctName");
                                                                                reserveFundAcctNo = rspBody111.getString("AcctNo");
                                                                                runOnUiThread(() -> {
                                                                                    dismissshowMakeHint();
                                                                                    //弹出输入取款信息
                                                                                    drawmoneyNumPopupView.show();
                                                                                });
                                                                            }

                                                                            @Override
                                                                            public void onError(String code, String msg) {
                                                                                showErr(msg);
                                                                            }
                                                                        });
                                                                    });
                                                                } else {
                                                                    runOnUiThread(() -> {
                                                                        showErr(msg);
                                                                    });
                                                                }

                                                            });

                                                }

                                                @Override
                                                public void onError(String code, String msg) {
                                                    showErr(msg);
                                                }
                                            });

                                        });
                                    }

                                    @Override
                                    public void onError(String code, String msg) {
                                        showErr(msg);
                                    }
                                });


                            });
                        }

                        @Override
                        public void onError(String code, String msg) {
                            showErr(msg);
                        }
                    });
                });
            }

            @Override
            public void onError(String code, String msg) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtils.showLong(msg);
                        dismissshowMakeHint();
                        inputpasswordPopupView = null;
                        inputpasswordPop = null;


                        inputpasswordPop = new InputPasswordPopup(ToHelpFarmersWithdrawMoneyActivity.this, ToHelpFarmersWithdrawMoneyActivity.this);

                        inputpasswordPopupView = new XPopup.Builder(ToHelpFarmersWithdrawMoneyActivity.this)
                                .dismissOnBackPressed(false)
                                .dismissOnTouchOutside(false)
                                .moveUpToKeyboard(false)
                                .isRequestFocus(false)
                                .hasShadowBg(false)
                                .hasStatusBarShadow(false)
                                .asCustom(inputpasswordPop);//
                        inputpasswordPopupView.show();
                    }
                });

            }
        });
    }

    /**
     * 输入金额之后
     *
     * @param money
     */
    @Override
    public void SendDrawMoneyNum(String money) {
        KLog.e("输入了金额之后   进行确认取款金额" + money);
        make_money = money;
        if (drawmoneyNumPopupView.isShow()) {
            drawmoneyNumPopupView.dismiss();
            //确定转账信息
            sureDealPopup = new SureDealPopup(this, this);
            sureDealPopupView = new XPopup.Builder(this)
                    .dismissOnBackPressed(false)
                    .dismissOnTouchOutside(false)
                    .moveUpToKeyboard(false)
                    .isRequestFocus(false)
                    .hasShadowBg(false)
                    .hasStatusBarShadow(false)
                    .asCustom(sureDealPopup);

            sureDealPopupView.show();
            sureDealPopup.setmCardNum(card_num);
            sureDealPopup.setmMoney(GetMoneyLvUtils.getInputMoney(money));
            sureDealPopup.setmUserName(card_username);
            sureDealPopup.setmOperation_name("本行助农取款");
        }
    }


    @Override
    public void initEvent(Bundle savedInstanceState) {
    }

    @OnClick({R.id.drawmoney_local, R.id.drawmoney_other})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.drawmoney_local:
                drawmoneyType = 0;
                readcardstart();//读卡操作
                break;
            case R.id.drawmoney_other:
                drawmoneyType = 1;
                readcardtwstart();
                break;
        }
        drawermoneyLayout.setVisibility(View.GONE);
    }

    /**
     * 读卡
     */
    private void readcardstart() {
        readCard(new HttpUtils.BaseReadCardListener() {
            @Override
            public void onSuccess(String data, String track2Data) {
                card_num = data;
                //如果选择本行卡交易  进行验证
                if (drawmoneyType == 0) {
                    //data  本行卡数据
                    //返回成功  输入密码ui
                    verifycardPopupView.show();
                    HttpUtilsV2.getCheckingThisBank(data, new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    verifycardPopupView.dismiss();
                                    KLog.e("进行验证本行卡数据,验证通过,进行输入密码");
                                    if (!inputpasswordPopupView.isShow()) {
                                        inputpasswordPopupView.show();
                                    }
                                }
                            });

                        }

                        @Override
                        public void onError(String code, String msg) {
                            showErr(msg);
                        }
                    });
                } else {
                    if (!inputpasswordPopupView.isShow()) {
                        inputpasswordPopupView.show();
                    }
                }
            }

            @Override
            public void onError(String msg) {
                showErr(msg);
            }
        });
    }


    /**
     * 读卡带密码键盘  他行
     */
    private void readcardtwstart() {
        tradeWithCards(new HttpUtils.BaseReadCardTwListener() {


            @Override
            public void onSuccess(String data, String track2Datas, String pin) {

                card_num = data;
                track2Data = track2Datas;

                cipassword = pin;
                doOtherBank();
            }

            @Override
            public void onError(String msg) {
                showErr(msg);
            }
        });
    }

    @Override
    public void OKPrint() {
        //交易成功打印凭条  确认打印纸张
        dealsuccessPopupView.dismiss();
//        surePrintPop.show();
        currencyDetectionPpView.show();
    }

    @Override
    public void ToPrint() {//执行打印操作
        surePrintPopupView.dismiss();
        printingPopupView.show();
        //请求电子印章
        HttpUtilsV2.getElectronicSeal("1", new HttpUtilsV2.NetCallBack() {
            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                runOnUiThread(() -> {
                    if (drawmoneyType == 0) {
                        //调用PrintUtil
                        PrintUtil.printThfwmOrElectronicCash(PosFuncs.getInstace(),
                                make_time,
                                "本行助农取款",
                                mServerSeqNo,
                                card_username,
                                card_num,
                                MoneyUtils.packRequest(make_money),
                                rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                    @Override
                                    public void success(String success) {
                                        PrintUtil.printThfwmOrElectronicCash2(PosFuncs.getInstace(),
                                                make_time,
                                                "本行助农取款",
                                                mServerSeqNo,
                                                card_username,
                                                card_num,
                                                MoneyUtils.packRequest(make_money),

                                                rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                                    @Override
                                                    public void success(String success) {
                                                        ToastUtils.showLong(success);
                                                        SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                        finish();
                                                    }

                                                    @Override
                                                    public void failed(String error) {
                                                        KLog.e(error);
                                                        showErr(error);
                                                    }
                                                });
                                    }

                                    @Override
                                    public void failed(String error) {
                                        showErr(error);
                                    }
                                }

                        );
                    } else {
                        //他行
                        PrintUtil.printThfwmOrElectronicCash(PosFuncs.getInstace(),
                                make_time,
                                "他行助农取款",
                                mServerSeqNo,
                                card_username,
                                reserveFundAcctNo,
                                MoneyUtils.packRequest(toherMakeMoney),
                                rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                    @Override
                                    public void success(String success) {
                                        PrintUtil.printThfwmOrElectronicCash2(PosFuncs.getInstace(),
                                                make_time,
                                                "他行助农取款",
                                                mServerSeqNo,
                                                card_username,
                                                reserveFundAcctNo,
                                                MoneyUtils.packRequest(toherMakeMoney),

                                                rspBody.getString("ImgBase64"), new PrintUtil.onPrintinterface() {
                                                    @Override
                                                    public void success(String success) {
                                                        ToastUtils.showLong(success);
                                                        SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                        finish();
                                                    }

                                                    @Override
                                                    public void failed(String error) {
                                                        showErr(error);
                                                    }
                                                });
                                    }

                                    @Override
                                    public void failed(String error) {
                                        showErr(error);
                                    }
                                }

                        );
                    }
                });


            }

            @Override
            public void onError(String code, String msg) {
                showErr(msg);
            }
        });


    }

    private void showErr(String msg) {
        runOnUiThread(() -> {
            errorPopup.setMsg(msg);
            errorPopupPpView.show();
        });
    }

    /**
     * 确认输入取款交易信息
     */
    @Override
    public void onNext() {
        KLog.e("点击了确认交易信息，进行取款交易");
        //确定交易信息
        sureDealPopupView.dismiss();
        if (!dealingPopupView.isShow()) {
            dealingPopupView.show();
        }

        //获取交易时间
        make_time = TimeUtils.getTimeData();
        HttpUtilsV2.getTransfer(card_num,
                card_username,
                reserveFundAcctNo,
                reserveFundAcctName,
                openBrcNo,
                cipassword,
                make_money,
                "1", "", "100001", new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        mServerSeqNo = ServerSeqNo;
                        consumerSeqNo = ConsumerSeqNo;
                        KLog.e(consumerSeqNo + "consumerSeqNo");
                        KLog.e("进行本行助农取款,交易成功,显示成功界面");
                        runOnUiThread(() -> {
                            dealingPopupView.dismiss();
                            dealsuccessPop.setMoney(make_money);
                            dealsuccessPop.setCardnum(card_num);
                            dealsuccessPop.setType("本行助农取款");
                            dealsuccessPop.setUsername(card_username);
                            dealsuccessPopupView.show();
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        ToastUtils.showLong(msg);
                        finish();
                    }
                });

    }

    /**
     * 不确认输入取款交易信息  返回上一步
     */
    @Override
    public void LastStep() {
        //不确定交易信息 点击之后返回上一部
        sureDealPopupView.dismiss();

        drawmoneyNumPop = new DrawMoneyNumPopup(this, this, this);
        drawmoneyNumPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(drawmoneyNumPop);//输入取款金额界面
        drawmoneyNumPopupView.show();

    }


    /**
     * 错误提示
     */
    @Override
    public void finished() {
        finish();
    }

    /**
     * 他行输入取款信息
     *
     * @param money
     */
    @Override
    public void HMoneyCall(String money) {
        toherMakeMoney = money;
        toHelpFarmersWithdrawOtherPpView.dismiss();


        sureToHelpFarmersWithdrawOtherPp = null;
        sureToHelpFarmersWithdrawOtherPpView = null;
        sureToHelpFarmersWithdrawOtherPp = new SureToHelpFarmersWithdrawOtherPp(this, this);
        sureToHelpFarmersWithdrawOtherPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(sureToHelpFarmersWithdrawOtherPp);

        sureToHelpFarmersWithdrawOtherPp.setCard_num(card_num);
        sureToHelpFarmersWithdrawOtherPp.setUser_name(card_username);
        sureToHelpFarmersWithdrawOtherPp.setUserbalance(otherUserBalance);
        sureToHelpFarmersWithdrawOtherPp.setMoneys(money);
        sureToHelpFarmersWithdrawOtherPp.setTitles("请确认您的取款信息");
        sureToHelpFarmersWithdrawOtherPpView.show();
    }

    /**
     * 他行交易
     */
    @Override
    public void sureFarmersCall() {
        make_time = TimeUtils.getTimeData();
        sureToHelpFarmersWithdrawOtherPpView.dismiss();
        showMakeHint("正在交易...");
        HttpUtilsV2.getTransferOfOtherCards(
                reserveFundAcctName,
                card_username,
                "051",
                reserveFundAcctNo,
                cipassword,
                toherMakeMoney,
                "",
                track2Data,
                card_num,
                new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        mServerSeqNo = ServerSeqNo;
                        consumerSeqNo = ConsumerSeqNo;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                dismissshowMakeHint();
                                dealsuccessPopupView.show();
                                dealsuccessPop.setType("他行助农取款");
                                dealsuccessPop.setMoney(toherMakeMoney);
                                dealsuccessPop.setUsername(card_username);
                                dealsuccessPop.setCardnum(card_num);
                            }
                        });

                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });


    }

    /**
     * 上一步
     */
    @Override
    public void notsure() {
        toHelpFarmersWithdrawOtherPp = null;
        toHelpFarmersWithdrawOtherPpView = null;

        toHelpFarmersWithdrawOtherPp = new ToHelpFarmersWithdrawOtherPp(this, this);
        toHelpFarmersWithdrawOtherPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(toHelpFarmersWithdrawOtherPp);

        toHelpFarmersWithdrawOtherPp.setCard_num(card_num);
        toHelpFarmersWithdrawOtherPp.setUser_name(card_username);
        toHelpFarmersWithdrawOtherPp.setUserbalance(otherUserBalance);
        toHelpFarmersWithdrawOtherPpView.show();
    }

    @Override
    public void CounterfeitCurrencyD() {
        currencyDetectionPpView.dismiss();
        readCcPViewpp.show();
        new Thread(() -> {
            String DATA = FtpReadFileUtils.FtpSingleFileData(
                    SPStaticUtils.getString("FTPIP"),
                    SPStaticUtils.getInt("FTPCOMPORT"),
                    SPStaticUtils.getString("FTPUSERNAME"),
                    SPStaticUtils.getString("FTPUSEPASSWORD"),
                    Api.FTPFILEADRESS,
                    Api.FTPFILE);


            if (!DATA.equals("")) {
                KLog.e(DATA + "DATA");
                String cccc = FtpReadFileUtils.analysisData(DATA);
                if (cccc != "") {

                    HttpUtilsV2.upGzAndWNum(consumerSeqNo, cccc, new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            runOnUiThread(() -> {
                                readCcPViewpp.dismiss();
                                if (!surePrintPopupView.isShow()) {
                                    surePrintPopupView.show();
                                }
                            });
                        }

                        @Override
                        public void onError(String code, String msg) {
                            runOnUiThread(() -> {
                                ToastUtils.showLong(msg);
                                readCcPViewpp.dismiss();
                                if (!surePrintPopupView.isShow()) {
                                    surePrintPopupView.show();
                                }
                            });
                        }
                    });

                } else {
                    runOnUiThread(() -> {
                        ToastUtils.showLong("冠字号数据错误");
                        readCcPViewpp.dismiss();
                        if (!surePrintPopupView.isShow()) {
                            surePrintPopupView.show();
                        }
                    });
                }
//
//
            } else {

                runOnUiThread(() -> {
                    KLog.e(DATA + "DATA");
                    ToastUtils.showLong("冠字号数据读取失败");
                    readCcPViewpp.dismiss();
                    if (!surePrintPopupView.isShow()) {
                        surePrintPopupView.show();
                    }
                });
            }
        }).start();


    }
}

